package gui;

import javax.swing.JPanel;
import javax.swing.JFrame;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.GridLayout;
import javax.swing.JButton;
import java.awt.Rectangle;
import java.awt.Point;
import javax.swing.JLabel;
import java.awt.event.KeyEvent;
import javax.swing.JOptionPane;
import javax.swing.JTextField;

import model.Service;


public class ReservedelOpretFrame extends JFrame {

	private static final long serialVersionUID = 1L;
	private JPanel jContentPane = null;
	private JPanel jPanel = null;
	private JPanel jPanel2 = null;
	private JPanel jPanel3 = null;
	private JPanel jPanel1 = null;
	private JPanel jPanel4 = null;
	private JButton jButtonOpret = null;
	private JButton jButtonCancel = null;
	private JLabel jLabelNavn = null;
	private JLabel jLabelIDNummer = null;
	private JTextField jTextFieldIDNummer = null;
	private JTextField jTextFieldNavn = null;
	private JPanel jPanel5 = null;
	private JPanel jPanel6 = null;
	private JPanel jPanel7 = null;
	private JPanel jPanel8 = null;
	private JLabel jLabelAntal = null;
	private JLabel jLabelPlacering = null;
	private JTextField jTextFieldAntal = null;
	private JTextField jTextFieldPlacering = null;
	private Frame parent = null;
	
	
	/**
	 * This is the default constructor
	 */
	public ReservedelOpretFrame() {
		super();
		initialize();
	}
	
	public void setParent(Frame parent)
	{
		this.parent = parent;
	}
	
	public void updateMainFrameReservedelsTypeList()
	{
		if(parent != null)
			((MainFrame) parent).updateReservedelList();
	}

	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		this.setSize(266, 297);
		this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		this.setContentPane(getJContentPane());
		this.setTitle("Opret Reservedel");	
	}

	/**
	 * This method initializes jContentPane
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getJContentPane() {
		if (jContentPane == null) {
			GridLayout gridLayout = new GridLayout();
			gridLayout.setRows(1);
			gridLayout.setColumns(2);
			jContentPane = new JPanel();
			jContentPane.setLayout(gridLayout);
			jContentPane.add(getJPanel(), null);
		}
		return jContentPane;
	}

	/**
	 * This method initializes jPanel
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getJPanel() {
		if (jPanel == null) {
			GridLayout gridLayout1 = new GridLayout();
			gridLayout1.setRows(2);
			jPanel = new JPanel();
			jPanel.setLayout(gridLayout1);
			jPanel.add(getJPanel2(), null);
			jPanel.add(getJPanel3(), null);
		}
		return jPanel;
	}

	/**
	 * This method initializes jPanel2
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getJPanel2() {
		if (jPanel2 == null) {
			GridLayout gridLayout2 = new GridLayout();
			gridLayout2.setRows(1);
			gridLayout2.setColumns(2);
			jPanel2 = new JPanel();
			jPanel2.setLayout(gridLayout2);
			jPanel2.add(getJPanel1(), null);
			jPanel2.add(getJPanel4(), null);
		}
		return jPanel2;
	}

	/**
	 * This method initializes jPanel3
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getJPanel3() {
		if (jPanel3 == null) {
			GridLayout gridLayout3 = new GridLayout();
			gridLayout3.setRows(2);
			jPanel3 = new JPanel();
			jPanel3.setLayout(gridLayout3);
			jPanel3.add(getJPanel5(), null);
			jPanel3.add(getJPanel5(), null);
			jPanel3.add(getJPanel6(), null);
		}
		return jPanel3;
	}

	/**
	 * This method initializes jPanel1
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getJPanel1() {
		if (jPanel1 == null) {
			jLabelIDNummer = new JLabel();
			jLabelIDNummer.setText("ID-Nummer");
			jLabelIDNummer.setBounds(new Rectangle(12, 68, 64, 16));
			jLabelIDNummer.setDisplayedMnemonic(KeyEvent.VK_UNDEFINED);
			jLabelNavn = new JLabel();
			jLabelNavn.setDisplayedMnemonic(KeyEvent.VK_UNDEFINED);
			jLabelNavn.setSize(new Dimension(28, 16));
			jLabelNavn.setLocation(new Point(12, 19));
			jLabelNavn.setText("Navn");
			jPanel1 = new JPanel();
			jPanel1.setLayout(null);
			jPanel1.add(jLabelNavn, null);
			jPanel1.add(jLabelIDNummer, null);
		}
		return jPanel1;
	}

	/**
	 * This method initializes jPanel4
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getJPanel4() {
		if (jPanel4 == null) {
			jPanel4 = new JPanel();
			jPanel4.setLayout(null);
			jPanel4.add(getJTextField1(), null);
			jPanel4.add(getJTextField(), null);
		}
		return jPanel4;
	}

	/**
	 * This method initializes jButton
	 * 
	 * @return javax.swing.JButton
	 */
	private JButton getJButton() {
		if (jButtonOpret == null) {
			jButtonOpret = new JButton();
			jButtonOpret.setText("Opret");
			jButtonOpret.setLocation(new Point(178, 28));
			jButtonOpret.setSize(new Dimension(66, 26));
			jButtonOpret.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					try
					{
						Service.getInstance().opretReservedelsType(jTextFieldNavn.getText(), Integer.parseInt(jTextFieldAntal.getText()), jTextFieldPlacering.getText());
						updateMainFrameReservedelsTypeList();
						jTextFieldNavn.setText("");
						jTextFieldAntal.setText("");
						jTextFieldPlacering.setText("");
						jTextFieldIDNummer.setText("" + Service.getInstance().getReservedelsId());
						
					}
					catch(Exception exception)
					{
						JOptionPane.showMessageDialog(ReservedelOpretFrame.this, "Mangler info", "!!Fejl!!", JOptionPane.ERROR_MESSAGE);
					}
					
				}
			});
		}
		return jButtonOpret;
	}

	/**
	 * This method initializes jButton1
	 * 
	 * @return javax.swing.JButton
	 */
	private JButton getJButton1() {
		if (jButtonCancel == null) {
			jButtonCancel = new JButton();
			jButtonCancel.setText("Cancel");
			jButtonCancel.setBounds(new Rectangle(7, 28, 73, 26));
			jButtonCancel.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					ReservedelOpretFrame.this.setVisible(false);
				}
			});
		}
		return jButtonCancel;
	}

	/**
	 * This method initializes jTextField
	 * 
	 * @return javax.swing.JTextField
	 */
	private JTextField getJTextField() {

		if (jTextFieldIDNummer == null) {
			jTextFieldIDNummer = new JTextField();
			jTextFieldIDNummer.setEditable(false);
			jTextFieldIDNummer.setEnabled(true);
			jTextFieldIDNummer.setBounds(new Rectangle(13, 64, 107, 22));
			jTextFieldIDNummer.setText("" + Service.getInstance().getReservedelsId());

		}
		return jTextFieldIDNummer;
	}

	/**
	 * This method initializes jTextField1
	 * 
	 * @return javax.swing.JTextField
	 */
	private JTextField getJTextField1() {
		if (jTextFieldNavn == null) {
			jTextFieldNavn = new JTextField();
			jTextFieldNavn.setEditable(true);
			jTextFieldNavn.setBounds(new Rectangle(13, 21, 107, 22));
			jTextFieldNavn.setEnabled(true);
		}
		return jTextFieldNavn;
	}

	/**
	 * This method initializes jPanel5
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getJPanel5() {
		if (jPanel5 == null) {
			GridLayout gridLayout4 = new GridLayout();
			gridLayout4.setRows(1);
			gridLayout4.setColumns(2);
			jPanel5 = new JPanel();
			jPanel5.setLayout(gridLayout4);
			jPanel5.add(getJPanel7(), null);
			jPanel5.add(getJPanel8(), null);

		}
		return jPanel5;
	}

	/**
	 * This method initializes jPanel6
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getJPanel6() {
		if (jPanel6 == null) {
			jPanel6 = new JPanel();
			jPanel6.setLayout(null);
			jPanel6.add(getJButton(), null);
			jPanel6.add(getJButton1(), null);
		}
		return jPanel6;
	}

	/**
	 * This method initializes jPanel7
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getJPanel7() {
		if (jPanel7 == null) {
			jLabelPlacering = new JLabel();
			jLabelPlacering.setText("Placering");
			jLabelPlacering.setSize(new Dimension(64, 16));
			jLabelPlacering.setLocation(new Point(3, 36));
			jLabelPlacering.setDisplayedMnemonic(KeyEvent.VK_UNDEFINED);
			jLabelPlacering.setVisible(true);
			jLabelAntal = new JLabel();
			jLabelAntal.setBounds(new Rectangle(3, 8, 64, 16));
			jLabelAntal.setText("Antal");
			jLabelAntal.setDisplayedMnemonic(KeyEvent.VK_UNDEFINED);
			jLabelAntal.setVisible(true);
			jPanel7 = new JPanel();
			jPanel7.setLayout(null);
			jPanel7.add(jLabelAntal, null);
			jPanel7.add(jLabelPlacering, null);
		}
		return jPanel7;
	}

	/**
	 * This method initializes jPanel8
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getJPanel8() {
		if (jPanel8 == null) {
			jPanel8 = new JPanel();
			jPanel8.setLayout(null);
			jPanel8.add(getJTextField11(), null);
			jPanel8.add(getJTextField12(), null);
		}
		return jPanel8;
	}

	/**
	 * This method initializes jTextField11
	 * 
	 * @return javax.swing.JTextField
	 */
	private JTextField getJTextField11() {
		if (jTextFieldAntal == null) {
			jTextFieldAntal = new JTextField();
			jTextFieldAntal.setBounds(new Rectangle(14, 8, 88, 20));
			jTextFieldAntal.setEditable(true);
			jTextFieldAntal.setVisible(true);
		}
		return jTextFieldAntal;
	}

	/**
	 * This method initializes jTextField12
	 * 
	 * @return javax.swing.JTextField
	 */
	private JTextField getJTextField12() {
		if (jTextFieldPlacering == null) {
			jTextFieldPlacering = new JTextField();
			jTextFieldPlacering.setEditable(true);
			jTextFieldPlacering.setLocation(new Point(14, 35));
			jTextFieldPlacering.setSize(new Dimension(88, 20));
			jTextFieldPlacering.setVisible(true);
		}
		return jTextFieldPlacering;
	}

}  //  @jve:decl-index=0:visual-constraint="305,33"
